package com.mata.worktime.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import com.mata.worktime.entity.user.Resource;
import com.mata.worktime.entity.user.User;
import com.mata.worktime.service.user.ResourceService;

import java.util.List;


/**
 * 主
 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 系统首页
     *
     * @param model 模型
     * @return 首页
     */
    @GetMapping("/")
    public String indexCopy(Model model)
    {
        // 取身份信息
        User user = getUser();
        // 根据用户id取出菜单
        List<Resource> resources = resourceService.selectResourcesByUser(user);
        model.addAttribute("resources", resources);
        model.addAttribute("user", user);
        return "index";
    }

    /**
     * 系统首页
     *
     * @param model 模型
     * @return 首页
     */
    @GetMapping("/index")
    public String index(Model model) {
        // 取身份信息
        User user = getUser();
        // 根据用户id取出菜单
        List<Resource> resources = resourceService.selectResourcesByUser(user);
        model.addAttribute("resources", resources);
        model.addAttribute("user", user);
        return "index";
    }

    /**
     * 默认main页面
     *
     * @return 主页面
     */
    @GetMapping("/main")
    public String main() {
        return "main";
    }
}
